package com.jxw.launcher.particle;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.exoplayer2.C;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jxw.constant.Constant;
import com.jxw.entity.AppInfoTG;
import com.jxw.launcher.Common;
import com.jxw.launcher.MyApp;
import com.jxw.launcher.R;
import com.jxw.launcher.util.Logger;
import com.jxw.launcher.util.SharedPreferencesUtil;
import com.jxw.launcher.util.UserData;
import com.jxw.launcher.util.Util;
import com.jxw.launcher.view.CommonDialog;
import com.jxw.launcher.view.QRCodeDialog;
import com.jxw.studyrecord.StudyRecordAPKInfo;
import com.jxw.studyrecord.StudyRecordMng;
import com.zzj.filedownloader.download.DownLoadListener;
import com.zzj.filedownloader.download.DownLoadManager;
import com.zzj.filedownloader.download.TaskInfo;
import com.zzj.filedownloader.download.dbcontrol.FileHelper;
import com.zzj.filedownloader.download.dbcontrol.bean.SQLDownLoadInfo;
import java.io.File;
import java.io.IOException;
import java.util.List;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONException;
import org.json.JSONObject;
import tv.danmaku.ijk.media.player.IjkMediaMeta;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;

/* loaded from: classes.dex */
public class ItemOnClickListener {
    private static final int MIN_CLICK_DELAY_TIME = 1000;
    private static final String TAG = "ItemOnClickListener";
    private static final String apkUrl = "http://api2.jiumentongbu.com/oss/getApkUrl?path=";
    private static long lastClickTime;
    private AlertDialog appUpdateDialog;
    Dialog dlg;
    private DownLoadManager downLoadManager;
    private boolean isTG = false;
    private onDownProssListener listener;
    private Context mContext;
    private Handler mHandler;

    /* loaded from: classes.dex */
    public interface onDownProssListener {
        void OnDowmListener();
    }

    public ItemOnClickListener(Context context) {
        this.mContext = null;
        this.mContext = context;
        this.mHandler = new Handler(this.mContext.getMainLooper());
        this.downLoadManager = new DownLoadManager(this.mContext);
        this.downLoadManager.setAllTaskListener(new DownloadManagerListener());
    }

    public void setContext(Context context) {
        this.mContext = context;
    }

    public void customClick(Context context, String str, String str2) {
        Intent intent = new Intent();
        intent.setClassName("com.jxw.laboratory", "com.jxw.laboratory.SYSActivity");
        intent.putExtra("StartArgs", str);
        intent.putExtra("grade", str2);
        context.startActivity(intent);
    }

    public void startZQSP(String str) {
        Intent intent = new Intent();
        intent.setComponent(new ComponentName("com.jxw.mskt.video", "com.jxw.mskt.video.VideoTopicActivity"));
        intent.putExtra("isTopic", true);
        intent.putExtra("isYYGJ", true);
        intent.putExtra(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL, Constant.DOMAIN3_OFFICIAL + str);
        intent.setFlags(276856832);
        this.mContext.startActivity(intent);
    }

    public static boolean isFastClick() {
        long currentTimeMillis = System.currentTimeMillis();
        boolean z = currentTimeMillis - lastClickTime <= 1000;
        lastClickTime = currentTimeMillis;
        return z;
    }

    /* JADX WARN: Can't wrap try/catch for region: R(14:177|(2:178|179)|(11:183|184|185|186|187|188|189|190|(2:192|193)|195|(2:197|198)(2:199|(2:201|202)(2:203|(4:205|206|207|209)(4:239|(3:241|242|243)|274|(4:276|277|278|280)(6:314|(3:316|317|318)|349|(1:580)(1:353)|354|(2:533|(4:535|536|537|539)(2:542|(4:544|545|546|548)(5:551|(4:554|(5:558|559|(1:561)|562|563)|565|552)|568|569|(1:575)(2:573|574))))(2:357|(2:531|532)(4:369|(2:371|(2:375|376))(2:519|(2:526|527))|381|(2:393|(2:405|(2:417|(2:429|(2:470|(2:506|(2:513|(2:515|516)(2:517|518))(1:512))(3:474|475|476))(3:435|436|(2:438|439)(2:440|441)))(4:421|422|423|425))(4:409|410|411|413))(4:397|398|399|401))(4:385|386|387|389))))))))|587|184|185|186|187|188|189|190|(0)|195|(0)(0)) */
    /* JADX WARN: Code restructure failed: missing block: B:182:0x035a, code lost:
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:184:0x035c, code lost:
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:185:0x035d, code lost:
        r18 = "gwj";
     */
    /* JADX WARN: Code restructure failed: missing block: B:188:0x0365, code lost:
        r0.printStackTrace();
     */
    /* JADX WARN: Removed duplicated region for block: B:180:0x0345 A[Catch: Exception -> 0x035a, TRY_LEAVE, TryCatch #15 {Exception -> 0x035a, blocks: (B:178:0x032c, B:180:0x0345), top: B:538:0x032c }] */
    /* JADX WARN: Removed duplicated region for block: B:191:0x03a3  */
    /* JADX WARN: Removed duplicated region for block: B:193:0x03a9  */
    /* JADX WARN: Removed duplicated region for block: B:41:0x0064  */
    /* JADX WARN: Removed duplicated region for block: B:51:0x00a2  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public void onClick(java.lang.String r20) {
        /*
            Method dump skipped, instructions count: 2798
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.jxw.launcher.particle.ItemOnClickListener.onClick(java.lang.String):void");
    }

    public boolean checkCiDianSource(final String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        final String str2 = str + ".bin";
        if (str.equals("汉字字典")) {
            str2 = str + ".JWDIC";
        }
        if (new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/ansystem/词典/" + str2).exists()) {
            return false;
        }
        Intent intent = new Intent();
        intent.setClassName("com.jxw.mskt.video", "com.jxw.mskt.video.MainActivity");
        intent.putExtra("shouldHide", true);
        try {
            this.mContext.startActivity(intent);
        } catch (Exception unused) {
        }
        new Handler().postDelayed(new Runnable() { // from class: com.jxw.launcher.particle.ItemOnClickListener.1
            @Override // java.lang.Runnable
            public void run() {
                Intent intent2 = new Intent();
                intent2.putExtra(IjkMediaMeta.IJKM_KEY_TYPE, "cd");
                intent2.putExtra("title", str);
                intent2.putExtra("bookName", str2);
                try {
                    intent2.setClassName("com.jxw.mskt.video", "com.jxw.mskt.video.DownloadService");
                    if (Build.VERSION.SDK_INT >= 26) {
                        ItemOnClickListener.this.mContext.startForegroundService(intent2);
                    } else {
                        ItemOnClickListener.this.mContext.startService(intent2);
                    }
                } catch (Exception e) {
                    Log.e("e:", e.getMessage());
                }
            }
        }, 200L);
        return true;
    }

    public void startActivitySafely(final String str, final String str2) {
        final CommonDialog commonDialog = new CommonDialog(this.mContext);
        commonDialog.setTitle(R.string.code_title);
        View inflate = LayoutInflater.from(this.mContext).inflate(R.layout.layout_input_edit, (ViewGroup) null);
        final EditText editText = (EditText) inflate.findViewById(R.id.edit_user);
        commonDialog.setContent(inflate);
        editText.setHint(this.mContext.getString(R.string.input_code_hint));
        commonDialog.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { // from class: com.jxw.launcher.particle.ItemOnClickListener.2
            @Override // android.content.DialogInterface.OnClickListener
            public void onClick(DialogInterface dialogInterface, int i) {
                try {
                    String parentPassword = UserData.getParentPassword();
                    String masterPassword = UserData.getMasterPassword();
                    String obj = editText.getText().toString();
                    if (TextUtils.isEmpty(obj)) {
                        return;
                    }
                    if ("mima".equals(obj)) {
                        new QRCodeDialog(ItemOnClickListener.this.mContext, masterPassword).show();
                        commonDialog.dismiss();
                        return;
                    }
                    if (!obj.equals(parentPassword) && !obj.equals(masterPassword)) {
                        Toast makeText = Toast.makeText(ItemOnClickListener.this.mContext, (int) R.string.input_code_wrong, 0);
                        TextView textView = (TextView) ((LinearLayout) makeText.getView()).getChildAt(0);
                        textView.setTextSize(ItemOnClickListener.this.mContext.getResources().getDimension(R.dimen.x25));
                        textView.setTextColor(ItemOnClickListener.this.mContext.getResources().getColor(R.color.black));
                        makeText.show();
                        return;
                    }
                    Intent intent = new Intent();
                    intent.setClassName(str, str2);
                    if (str.equals("com.feimi.browser")) {
                        intent = ItemOnClickListener.this.mContext.getPackageManager().getLaunchIntentForPackage("com.feimi.browser");
                        ItemOnClickListener.this.mContext.startActivity(intent);
                    }
                    intent.addFlags(32768);
                    ItemOnClickListener.this.mContext.startActivity(intent);
                    commonDialog.dismiss();
                } catch (ActivityNotFoundException e) {
                    e.printStackTrace();
                    str.contains("launcher3");
                    if (str2.equals("com.android.launcher3.uioverrides.QuickstepLauncher")) {
                        try {
                            Intent intent2 = new Intent();
                            intent2.setClassName(str, "com.android.launcher3.Launcher");
                            ItemOnClickListener.this.mContext.startActivity(intent2);
                            commonDialog.dismiss();
                            return;
                        } catch (ActivityNotFoundException e2) {
                            e2.printStackTrace();
                            try {
                                try {
                                    try {
                                        try {
                                            Intent intent3 = new Intent();
                                            intent3.setClassName(str, "com.android.searchlauncher.SearchLauncher");
                                            ItemOnClickListener.this.mContext.startActivity(intent3);
                                            commonDialog.dismiss();
                                            return;
                                        } catch (ActivityNotFoundException unused) {
                                            Intent intent4 = new Intent();
                                            intent4.setClassName(str, "com.android.launcher3.ESLauncher");
                                            ItemOnClickListener.this.mContext.startActivity(intent4);
                                            commonDialog.dismiss();
                                            return;
                                        }
                                    } catch (ActivityNotFoundException unused2) {
                                        Intent intent5 = new Intent();
                                        intent5.setClassName(str, "com.android.launcher3.Launcher3QuickStepGo");
                                        ItemOnClickListener.this.mContext.startActivity(intent5);
                                        return;
                                    }
                                } catch (ActivityNotFoundException unused3) {
                                    Intent intent6 = new Intent();
                                    intent6.setClassName("com.huawei.android.launcher", "com.huawei.android.launcher.unihome.UniHomeLauncher");
                                    ItemOnClickListener.this.mContext.startActivity(intent6);
                                    return;
                                }
                            } catch (ActivityNotFoundException unused4) {
                                Toast.makeText(ItemOnClickListener.this.mContext, "Application not found", 0).show();
                                return;
                            }
                        }
                    }
                    Toast.makeText(ItemOnClickListener.this.mContext, "Application not found", 0).show();
                }
            }
        });
        commonDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { // from class: com.jxw.launcher.particle.ItemOnClickListener.3
            @Override // android.content.DialogInterface.OnClickListener
            public void onClick(DialogInterface dialogInterface, int i) {
                commonDialog.cancel();
            }
        });
        commonDialog.show();
    }

    private void startActivity(String str, String str2, String str3) {
        startActivity(str, str2, null, null, str3);
    }

    private void startActivity(String str, String str2, String str3, String str4, String str5) {
        boolean z;
        Log.e("1111", "222222222");
        try {
            Intent intent = new Intent();
            intent.setClassName(str, str2);
            intent.setFlags(276856832);
            if (str3 != null) {
                intent.putExtra("StartArgs", str3);
            }
            intent.putExtra("InPrimary", true);
            StudyRecordMng.startCount(this.mContext, str, str2, str3, true);
            this.mContext.startActivity(intent);
        } catch (Exception e) {
            Log.e("exp:", e.toString());
            if (str2.equals("com.jxw.online_study.activity.InterestingLanguageActivity")) {
                startActivity("com.jxw.qwyw", "com.jxw.qwyw.MainActivity", null);
            } else if (str2.equals("com.android.launcher3.uioverrides.QuickstepLauncher")) {
                try {
                    try {
                        try {
                            try {
                                try {
                                    Intent intent2 = new Intent();
                                    intent2.setClassName(str, "com.android.launcher3.Launcher");
                                    this.mContext.startActivity(intent2);
                                } catch (ActivityNotFoundException unused) {
                                    Intent intent3 = new Intent();
                                    intent3.setClassName(str, "com.android.launcher3.Launcher3QuickStepGo");
                                    this.mContext.startActivity(intent3);
                                }
                            } catch (ActivityNotFoundException unused2) {
                                Toast.makeText(this.mContext, "Application not found", 0).show();
                            }
                        } catch (ActivityNotFoundException unused3) {
                            Intent intent4 = new Intent();
                            intent4.setClassName(str, "com.android.searchlauncher.SearchLauncher");
                            this.mContext.startActivity(intent4);
                        }
                    } catch (ActivityNotFoundException unused4) {
                        Intent intent5 = new Intent();
                        intent5.setClassName(str, "com.android.launcher3.ESLauncher");
                        this.mContext.startActivity(intent5);
                    }
                } catch (ActivityNotFoundException unused5) {
                    Intent intent6 = new Intent();
                    intent6.setClassName("com.huawei.android.launcher", "com.huawei.android.launcher.unihome.UniHomeLauncher");
                    this.mContext.startActivity(intent6);
                }
            } else {
                StudyRecordMng.clearCount();
                try {
                    String str6 = Environment.getExternalStorageDirectory().getCanonicalPath() + "/appResource/";
                    Logger.getLogger().d(str6);
                    z = findAndInstallFiles(str6, str);
                } catch (IOException e2) {
                    e2.printStackTrace();
                    z = false;
                }
                if (z) {
                    return;
                }
                if ("com.android.camera.CameraLauncher".equals(str2)) {
                    Intent intent7 = new Intent();
                    intent7.setAction("android.media.action.STILL_IMAGE_CAMERA");
                    try {
                        this.mContext.startActivity(intent7);
                    } catch (Exception unused6) {
                        Toast.makeText(this.mContext, "Application not found", 0).show();
                    }
                } else if (StudyRecordAPKInfo.CLASS_PHOTO.equals(str2)) {
                    Intent intent8 = new Intent("android.intent.action.VIEW");
                    intent8.setType("vnd.android.cursor.dir/image");
                    intent8.setType("vnd.android.cursor.dir/video");
                    try {
                        this.mContext.startActivity(intent8);
                    } catch (Exception unused7) {
                        Toast.makeText(this.mContext, "Application not found", 0).show();
                    }
                } else if (TextUtils.isEmpty(str4)) {
                } else {
                    showDownloadDialog(str4, str5, null);
                }
            }
        }
    }

    public String getAPKPackageName(Context context, String str) {
        PackageInfo packageArchiveInfo = context.getPackageManager().getPackageArchiveInfo(str, 1);
        String str2 = packageArchiveInfo != null ? packageArchiveInfo.packageName : null;
        Logger logger = Logger.getLogger();
        logger.d("path=" + str + ",getAPKPackageName=" + str2);
        return str2;
    }

    private void showDownloadDialog(final String str, final String str2, final String str3) {
        Log.i(TAG, "showDownloadDialog: " + str + "::" + str2);
        final Dialog dialog = new Dialog(this.mContext, R.style.ActionSheet);
        Window window = dialog.getWindow();
        View inflate = ((LayoutInflater) this.mContext.getSystemService("layout_inflater")).inflate(R.layout.download_dialog, (ViewGroup) null);
        TextView textView = (TextView) inflate.findViewById(R.id.download_cancel);
        TextView textView2 = (TextView) inflate.findViewById(R.id.tag_title);
        if (!TextUtils.isEmpty(str2)) {
            textView2.setText("未安装\"" + str2 + "\",下载后可继续使用!");
        }
        TextView textView3 = (TextView) inflate.findViewById(R.id.download_ok);
        textView.setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.particle.ItemOnClickListener.4
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                ItemOnClickListener itemOnClickListener = ItemOnClickListener.this;
                if (itemOnClickListener.isValidContext(itemOnClickListener.mContext)) {
                    dialog.dismiss();
                }
            }
        });
        textView3.setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.particle.ItemOnClickListener.5
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                if (ItemOnClickListener.this.isTG && !TextUtils.isEmpty(str3)) {
                    Log.d("确定下载", "sssss");
                    new Thread(new Runnable() { // from class: com.jxw.launcher.particle.ItemOnClickListener.5.1
                        @Override // java.lang.Runnable
                        public void run() {
                            List list = (List) new Gson().fromJson(SharedPreferencesUtil.getString(ItemOnClickListener.this.mContext, SharedPreferencesUtil.TG_APP_INFO, ""), new TypeToken<List<AppInfoTG.DataDTO>>() { // from class: com.jxw.launcher.particle.ItemOnClickListener.5.1.1
                            }.getType());
                            if (list.size() > 0) {
                                AppInfoTG.DataDTO dataDTO = new AppInfoTG.DataDTO();
                                boolean z = false;
                                for (int i = 0; i < list.size(); i++) {
                                    if (((AppInfoTG.DataDTO) list.get(i)).getAppName().equals(str)) {
                                        dataDTO = (AppInfoTG.DataDTO) list.get(i);
                                        z = true;
                                    }
                                }
                                if (z) {
                                    ItemOnClickListener.this.Buriedpoint(dataDTO);
                                }
                            }
                        }
                    }).start();
                    ItemOnClickListener.this.getDownloadUrl(str, str3, str2, false, true);
                } else {
                    ItemOnClickListener itemOnClickListener = ItemOnClickListener.this;
                    String str4 = str;
                    itemOnClickListener.getDownloadUrl(str4, ItemOnClickListener.apkUrl + str + ".apk", str2, false, false);
                }
                dialog.dismiss();
                Log.e("apkurl1", ItemOnClickListener.apkUrl);
            }
        });
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.x = 0;
        attributes.y = 0;
        attributes.gravity = 17;
        dialog.onWindowAttributesChanged(attributes);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(inflate);
        if (isValidContext(this.mContext)) {
            dialog.show();
        }
        window.setAttributes(attributes);
    }

    private boolean findAndInstallFiles(String str, String str2) {
        File[] listFiles = new File(str).listFiles();
        if (listFiles == null) {
            return false;
        }
        for (File file : listFiles) {
            if (file.isFile()) {
                if (file.getPath().toLowerCase().endsWith(".apk") && str2.equals(getAPKPackageName(this.mContext, file.getPath()))) {
                    installApp(file, this.mContext);
                    return true;
                }
            } else if (file.isDirectory()) {
                findAndInstallFiles(file.getPath(), str2);
            }
        }
        return false;
    }

    public void installApp(File file, Context context) {
        Intent intent = new Intent();
        intent.addFlags(C.ENCODING_PCM_MU_LAW);
        Logger logger = Logger.getLogger();
        logger.d("file=" + file.getAbsolutePath());
        intent.setAction("android.intent.action.VIEW");
        if (Build.VERSION.SDK_INT >= 24) {
            Uri uriForFile = FileProvider.getUriForFile(context, "com.jxw.launcher.fileprovider", file);
            intent.addFlags(1);
            intent.setDataAndType(uriForFile, "application/vnd.android.package-archive");
        } else {
            intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
        }
        try {
            context.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void downInstallApk(String str, String str2, String str3) {
        try {
            File file = new File(FileHelper.getTempDirPath() + str + ".apk");
            if (file.exists()) {
                Logger logger = Logger.getLogger();
                logger.d("deleteTask=" + file.getAbsolutePath());
                file.delete();
            }
            File file2 = new File(FileHelper.getTempDirPath() + str);
            if (file2.exists()) {
                Logger logger2 = Logger.getLogger();
                logger2.d("deleteTask=" + file2.getAbsolutePath());
                file2.delete();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.downLoadManager.setSupportBreakpoint(true);
        DownLoadManager downLoadManager = this.downLoadManager;
        downLoadManager.addTask(str, str2, str, FileHelper.baseFilePath + str + ".apk");
        this.downLoadManager.startTask(str);
        showDownloadingDialog(str, str3);
    }

    public boolean isAppInstalled(Context context, String str) {
        try {
            context.getPackageManager().getPackageInfo(str, 1);
            return true;
        } catch (PackageManager.NameNotFoundException unused) {
            return false;
        }
    }

    private void showDownloadingDialog(final String str, final String str2) {
        Log.i(TAG, "showDownloadidngDialog: ");
        this.dlg = new Dialog(this.mContext, R.style.ActionSheet);
        Window window = this.dlg.getWindow();
        View inflate = ((LayoutInflater) this.mContext.getSystemService("layout_inflater")).inflate(R.layout.downloading_dialog, (ViewGroup) null);
        TextView textView = (TextView) inflate.findViewById(R.id.tag_name);
        if (!TextUtils.isEmpty(str2)) {
            textView.setText(str2);
        }
        final ProgressBar progressBar = (ProgressBar) inflate.findViewById(R.id.download_progressbar);
        final TextView textView2 = (TextView) inflate.findViewById(R.id.download_pro);
        ((TextView) inflate.findViewById(R.id.downloading_back)).setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.particle.ItemOnClickListener.6
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                ItemOnClickListener itemOnClickListener = ItemOnClickListener.this;
                if (itemOnClickListener.isValidContext(itemOnClickListener.mContext)) {
                    ItemOnClickListener.this.dlg.dismiss();
                }
            }
        });
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.x = 0;
        attributes.y = 0;
        attributes.gravity = 17;
        this.dlg.onWindowAttributesChanged(attributes);
        this.dlg.setCanceledOnTouchOutside(true);
        this.dlg.setContentView(inflate);
        if (isValidContext(this.mContext)) {
            this.dlg.show();
            final Runnable runnable = new Runnable() { // from class: com.jxw.launcher.particle.ItemOnClickListener.7
                @Override // java.lang.Runnable
                public void run() {
                    TaskInfo taskInfo = ItemOnClickListener.this.downLoadManager.getTaskInfo(str);
                    if (taskInfo != null && taskInfo.getProgress() < 100) {
                        if (textView2 != null) {
                            if (taskInfo.isOnDownloading()) {
                                textView2.setText(ItemOnClickListener.this.mContext.getString(R.string.downloading_message, str2, Integer.valueOf(taskInfo.getProgress())));
                                progressBar.setProgress(taskInfo.getProgress());
                            } else {
                                textView2.setText(ItemOnClickListener.this.mContext.getString(R.string.downloading_pause, str2));
                                ItemOnClickListener.this.downLoadManager.startTask(taskInfo.getTaskID());
                            }
                        }
                        ItemOnClickListener.this.mHandler.postDelayed(this, 1000L);
                        return;
                    }
                    ItemOnClickListener itemOnClickListener = ItemOnClickListener.this;
                    if (itemOnClickListener.isValidContext(itemOnClickListener.mContext)) {
                        ItemOnClickListener.this.dlg.isShowing();
                    }
                }
            };
            this.mHandler.post(runnable);
            this.dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { // from class: com.jxw.launcher.particle.ItemOnClickListener.8
                @Override // android.content.DialogInterface.OnDismissListener
                public void onDismiss(DialogInterface dialogInterface) {
                    Logger.getLogger().d("onDismiss");
                    ItemOnClickListener.this.mHandler.removeCallbacks(runnable);
                }
            });
        }
        window.setAttributes(attributes);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public boolean isValidContext(Context context) {
        Activity activity = (Activity) context;
        if (activity.isDestroyed() || activity.isFinishing()) {
            Log.i("YXH", "Activity is invalid. isDestoryed-->" + activity.isDestroyed() + " isFinishing-->" + activity.isFinishing());
            return false;
        }
        return true;
    }

    /* loaded from: classes.dex */
    private class DownloadManagerListener implements DownLoadListener {
        private DownloadManagerListener() {
        }

        @Override // com.zzj.filedownloader.download.DownLoadListener
        public void onStart(SQLDownLoadInfo sQLDownLoadInfo) {
            Logger logger = Logger.getLogger();
            logger.d("onStart,name=" + sQLDownLoadInfo.getTaskID());
        }

        @Override // com.zzj.filedownloader.download.DownLoadListener
        public void onProgress(SQLDownLoadInfo sQLDownLoadInfo, boolean z) {
            TaskInfo taskInfo = ItemOnClickListener.this.downLoadManager.getTaskInfo(sQLDownLoadInfo.getTaskID());
            if (taskInfo != null) {
                taskInfo.setDownFileSize(sQLDownLoadInfo.getDownloadSize());
                taskInfo.setFileSize(sQLDownLoadInfo.getFileSize());
                taskInfo.setOnDownloading(true);
            }
            Logger logger = Logger.getLogger();
            logger.d("onProgress,name=" + sQLDownLoadInfo.getTaskID() + ",size=" + sQLDownLoadInfo.getDownloadSize());
        }

        @Override // com.zzj.filedownloader.download.DownLoadListener
        public void onStop(SQLDownLoadInfo sQLDownLoadInfo, boolean z) {
            Logger logger = Logger.getLogger();
            logger.d("onStop,name=" + sQLDownLoadInfo.getTaskID());
        }

        @Override // com.zzj.filedownloader.download.DownLoadListener
        public void onSuccess(final SQLDownLoadInfo sQLDownLoadInfo) {
            Logger logger = Logger.getLogger();
            logger.d("onSuccess,name=" + sQLDownLoadInfo.getTaskID() + ",name:" + sQLDownLoadInfo.getFileName());
            ItemOnClickListener itemOnClickListener = ItemOnClickListener.this;
            if (itemOnClickListener.isValidContext(itemOnClickListener.mContext) && ItemOnClickListener.this.dlg != null) {
                ItemOnClickListener.this.dlg.dismiss();
            }
            new Thread(new Runnable() { // from class: com.jxw.launcher.particle.ItemOnClickListener.DownloadManagerListener.1
                @Override // java.lang.Runnable
                public void run() {
                    List list = (List) new Gson().fromJson(SharedPreferencesUtil.getString(ItemOnClickListener.this.mContext, SharedPreferencesUtil.TG_APP_INFO, ""), new TypeToken<List<AppInfoTG.DataDTO>>() { // from class: com.jxw.launcher.particle.ItemOnClickListener.DownloadManagerListener.1.1
                    }.getType());
                    try {
                        if (list.size() > 0) {
                            AppInfoTG.DataDTO dataDTO = new AppInfoTG.DataDTO();
                            boolean z = false;
                            for (int i = 0; i < list.size(); i++) {
                                if (((AppInfoTG.DataDTO) list.get(i)).getAppName().equals(sQLDownLoadInfo.getFileName())) {
                                    dataDTO = (AppInfoTG.DataDTO) list.get(i);
                                    z = true;
                                }
                            }
                            if (z) {
                                ItemOnClickListener.this.getdownloads(dataDTO);
                            }
                        }
                    } catch (Exception unused) {
                    }
                }
            }).start();
            ItemOnClickListener.this.installApp(new File(sQLDownLoadInfo.getFilePath()), ItemOnClickListener.this.mContext);
        }

        @Override // com.zzj.filedownloader.download.DownLoadListener
        public void onError(SQLDownLoadInfo sQLDownLoadInfo) {
            Logger logger = Logger.getLogger();
            logger.d("onError,name=" + sQLDownLoadInfo.getTaskID());
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void getDownloadUrl(final String str, final String str2, final String str3, final boolean z, boolean z2) {
        String str4;
        OkHttpClient okHttpClient = new OkHttpClient();
        if (z2) {
            Log.d("进入下载", "sssssssssssss");
            downInstallApk(str, str2, str3);
            return;
        }
        if (z) {
            str4 = str2 + "&source=oss";
        } else {
            str4 = str2;
        }
        Log.i(TAG, "getDownloadUrl: " + str4);
        okHttpClient.newCall(new Request.Builder().url(str4).build()).enqueue(new Callback() { // from class: com.jxw.launcher.particle.ItemOnClickListener.9
            @Override // okhttp3.Callback
            public void onFailure(Call call, IOException iOException) {
                Log.d("zzj", "onFailure=" + iOException.getMessage());
                ItemOnClickListener.this.mHandler.post(new Runnable() { // from class: com.jxw.launcher.particle.ItemOnClickListener.9.1
                    @Override // java.lang.Runnable
                    public void run() {
                        if (!z) {
                            ItemOnClickListener.this.getDownloadUrl(str, str2, str3, true, false);
                            Log.d("正在下载", "xxxxxxxxxxxxxxxxxxxxxx");
                            return;
                        }
                        ItemOnClickListener.this.showDialog("获取下载地址失败");
                    }
                });
            }

            @Override // okhttp3.Callback
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    final String string = response.body().string();
                    Log.d("zzj", "获取下载地址成功了:" + string);
                    ItemOnClickListener.this.mHandler.post(new Runnable() { // from class: com.jxw.launcher.particle.ItemOnClickListener.9.2
                        @Override // java.lang.Runnable
                        public void run() {
                            try {
                                JSONObject jSONObject = new JSONObject(string);
                                if (jSONObject.optBoolean("success")) {
                                    String optString = jSONObject.optString(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL);
                                    Log.i(ItemOnClickListener.TAG, "rund: " + optString);
                                    ItemOnClickListener.this.downInstallApk(str, optString, str3);
                                    return;
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            if (!z) {
                                ItemOnClickListener.this.getDownloadUrl(str, str2, str3, true, false);
                            } else {
                                ItemOnClickListener.this.showDialog("获取下载地址失败");
                            }
                        }
                    });
                }
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void getdownloads(AppInfoTG.DataDTO dataDTO) {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request.Builder builder = new Request.Builder();
        Request build = builder.url(Util.DOWNLOAD_NUM + "id=" + dataDTO.getId()).build();
        Log.i(TAG, "appInfos: 1111111111111111");
        okHttpClient.newCall(build).enqueue(new Callback() { // from class: com.jxw.launcher.particle.ItemOnClickListener.10
            @Override // okhttp3.Callback
            public void onFailure(Call call, IOException iOException) {
                Log.i(ItemOnClickListener.TAG, "appInfos: 22222222222222222222222");
                Log.d("", "login onFailure=" + iOException.getMessage());
            }

            @Override // okhttp3.Callback
            public void onResponse(Call call, Response response) throws IOException {
                Log.d("getdownloads", "response=" + response.body().string());
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void Buriedpoint(AppInfoTG.DataDTO dataDTO) {
        OkHttpClient okHttpClient = new OkHttpClient();
        String str = Util.APP_MARK_ADD + "appid=" + dataDTO.getPackageName() + "&apkisbn=zngbgkptv5&deviceid=" + MyApp.getInstance().series + "&actiontype=2&actionstate=0&token=" + Common.readToken(this.mContext) + "&actionTypeDetail=201";
        Logger.getLogger().e("url:" + str);
        Request build = new Request.Builder().url(str).build();
        Log.i(TAG, "appInfos: 1111111111111111");
        okHttpClient.newCall(build).enqueue(new Callback() { // from class: com.jxw.launcher.particle.ItemOnClickListener.11
            @Override // okhttp3.Callback
            public void onFailure(Call call, IOException iOException) {
                Log.i(ItemOnClickListener.TAG, "appInfos: 22222222222222222222222");
                Log.d("", "login onFailure=" + iOException.getMessage());
            }

            @Override // okhttp3.Callback
            public void onResponse(Call call, Response response) throws IOException {
                Log.d("getdownloads", "onResponse=" + response.body().string());
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void showDialog(String str) {
        if (isValidContext(this.mContext)) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this.mContext);
            builder.setMessage(str);
            builder.setTitle("提示");
            builder.create().show();
        }
    }

    public void setListener(onDownProssListener ondownprosslistener) {
        this.listener = ondownprosslistener;
    }
}
